﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MpSoft.Library.BUSS.Categories;
using MpSoft.Library.DTO;

namespace MpSoft.Web.AdminCP.Controls.Modules
{
    public partial class NavigationLeftBar : System.Web.UI.UserControl
    {
        #region var

        private string controlName = string.Empty;

        #endregion

        #region Method

        protected string GetNavLeft()
        {
            return NavLeft(NavigateBUSS.Navigate_List());
        }

        private string NavLeft(List<ENavigate> AllNav)
        {
            var NavFirst = NavigateBUSS.Navigate_ByParent("", AllNav);
            if (NavFirst != null)
            {
                StringBuilder sb = new StringBuilder();
                int ix = 1;
                foreach (var obj in NavFirst)
                {
                    sb.Append("<div class='subnav" + (ix > 3 ? " subnav-hidden" : "") + "'>");
                    sb.Append("<div class='subnav-title'><a href='#' class='toggle-subnav'><i class='fa fa-angle-down'></i><span>" + obj.Title + "</span></a></div>");
                    sb.Append(SubNavLeft(obj.ID, AllNav));
                    sb.Append("</div>");
                    ix++;
                }
                return sb.ToString();
            }
            return "";
        }

        private string SubNavLeft(string parent, List<ENavigate> AllNav)
        {
            var subList = NavigateBUSS.Navigate_ByParent(parent, AllNav);
            if (subList != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<ul class='subnav-menu'>");
                foreach (var obj in subList)
                {
                    sb.Append("<li>");
                    sb.Append("<a href='" + obj.Url + "'>" + obj.Title + "</a>");
                    sb.Append(SubNavLeft(obj.ID, AllNav));
                    sb.Append("</li>");
                }
                sb.Append("</ul>");
                return sb.ToString();
            }
            return "";

        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #endregion

        #region Properties

        public string ControlName
        {
            set { controlName = value; }
            get { return controlName; }
        }

        #endregion
    }
}